package com.ruoyi.web.controller.common;

import cn.hutool.core.lang.Validator;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.framework.service.SmsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author liutao
 * @version 1.0
 * @description: TODO
 * @date 2024/3/13 01:27
 */
@RestController
@RequestMapping("/api")
public class SmsController {

    @Resource
    private SmsService smsService;

    @GetMapping("/getMobileCode")
    public R<String> getMobileCode(@RequestParam String phone, @RequestParam int type) {
        boolean isValid = Validator.isMobile(phone);
        if (!isValid) {
            return R.fail("手机号码错误");
        }
        return R.ok(smsService.sendSms(phone,type));
    }
}
